﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Slock.Rendering;
using Microsoft.Xna.Framework;

namespace Slock.GameObjects.ActorComponents
{
    /// <summary>
    /// Encapsulates the StaticMeshRenderer inside of an actor component for easy use
    /// <remarks>DOES NOT EASILY SUPPORT DYNAMIC ACTORS, DOING SO WOULD CAUSE SLOWDOWNS</remarks>
    /// </summary>
    public class StaticMeshRendererComponent : RenderComponent, IDisposable
    {
        IRenderer renderer;
        Effect shaderEffect;

        /// <summary>
        /// Initializes a new instance of StaticMeshRenderer
        /// </summary>
        /// <param name="ownerActor"></param>
        public StaticMeshRendererComponent(Actor ownerActor) : base(ownerActor)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="indices"></param>
        public void Initalize(ref VertexBuffer buffer, ref IndexBuffer indices)
        {
            this.Dispose();
            this.renderer = new StaticVertexBufferRenderer(this.Owner.World, ref buffer, ref indices);
        }

        /// <summary>
        /// Draws this component
        /// </summary>
        /// <param name="projection"></param>
        /// <param name="view"></param>
        /// <param name="delta"></param>
        public override void Draw(float delta, Matrix view, Matrix projection)
        {
            if(Enabled)
                renderer.Draw(delta, view, projection);
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            if (renderer != null)
                renderer.Dispose();
        }
    }
}
